package com.tzjz.dto;

import java.io.Serializable;

/**
 * @author renshuting
 * @date 2024/1/6 13:03
 */
public class Result<T> implements Serializable {
    //响应编码
    private String code;
    /**
     * 信息内容
     */
    private String msg;
    /**
     * 数据
     */
    private T data;

    public Result(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result() {
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


    public static <T> Result<T> success() {
        Result<T> ret = new Result<T>();
        ret.setCode("0");
        ret.setMsg("成功");
        return ret;
    }

    public static <T> Result<T> success(T data) {
        Result<T> ret = Result.success();
        ret.setData(data);
        return ret;
    }

    public static <T> Result<T> fail() {
        Result<T> ret = new Result<T>();
        ret.setCode("500");
        ret.setMsg("服务发生异常");
        return ret;
    }

    public static <T> Result<T> failMessage(String msg) {
        Result<T> ret = Result.fail();
        ret.setMsg(msg);
        return ret;
    }
}
